//
//  ViewController.m
//  JM
//
//  Created by My Mac on 16/6/3.
//  Copyright © 2016年 My Mac. All rights reserved.
//

#import "ViewController.h"
#import "TwoViewController.h"
#import "EditViewController.h"

@interface ViewController ()<EditDelegate>


@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.navigationItem.title = @"我的导航标题";//标题编辑
    
    //self.view.backgroundColor = [UIColor redColor];//改背景颜色
    
    //self.tableView.bounces= NO;//控制上拉下拉的那个弹簧,使它不能拖
    
    self.refreshControl = [UIRefreshControl new];//向下拉刷新
    self.refreshControl.tintColor=[UIColor redColor];//改变刷新图标的颜色
    
    self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"我在刷新呢" attributes:@{NSForegroundColorAttributeName:[UIColor redColor]}];//刷新图标下写的文字的颜色
    
    //self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"结束刷新按钮" style:UIBarButtonItemStylePlain target:self action:@selector(onClick:)];//在导航栏右侧设置一个自定义的文字按钮,此按钮是使它结束刷新的按钮
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(onClick:)];//是刷新停止按钮为照相机图标，实现与上面同样的功能
    //self.navigationItem
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"5"] style:UIBarButtonItemStylePlain target:self action:@selector(onClick:)];//刷新按钮变为图片5
    UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"5"]];
    self.navigationItem.titleView = iv;//标题从文字改为图片
    
}//这个函数就是控制基本的视图

-(void)onClick:(id)sender{
    [self.refreshControl endRefreshing];
}

-(NSInteger)tableView:(UITableView *)tableView  numberOfRowsInSection:(NSInteger)section{
    return 5;//改变此值就改变了表格的行数
}//制作出来的表格行数

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];//初始化并选择它的分格
    
    NSString *imgName = [NSString stringWithFormat:@"%ld",indexPath.row +1];//从0开始，每行＋1
    cell.imageView.image = [UIImage imageNamed:imgName];//添加图标,UIImage专门管理图片的一个类，imageView显示图片的一个类
    
    cell.imageView.layer.cornerRadius =18;//把图标切成圆圆的
    cell.imageView.clipsToBounds = YES;//要是没切成功，则需要这行
    
    cell.textLabel.text = @"哈哈";
    
    cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;//让表格右边有箭头
    if(indexPath.row == 3){
        UISwitch *swi = [UISwitch new];
        [swi sizeToFit];
        cell.accessoryView = swi;
    }
    
    return cell;
}//这个函数是你定义表格的属性，就是说控制里面有什么东西

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //TwoViewController *con = [TwoViewController new];
    //ViewController *con = [ViewController new];//只是最简单的初始化
    EditViewController *con = [[EditViewController alloc] initWithStyle:UITableViewStyleGrouped];
    con.delegate = self;
    con.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:con animated:YES];//点进去无限弹出自己
    
    
}
- (void)inputString:(NSString *)text
{
    NSLog(@"输入了：%@",text);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
